package com.etang.homeproject2.tools;

import com.etang.homeproject2.ResourceTable;
import ohos.agp.components.DirectionalLayout;
import ohos.agp.components.LayoutScatter;
import ohos.agp.utils.LayoutAlignment;
import ohos.agp.window.dialog.IDialog;
import ohos.agp.window.dialog.ToastDialog;
import ohos.app.Context;

/**
 * 自定义Toast
 */
public class DiyToast {
    //新建ToastDialog
    private static ToastDialog toastDialog;

    /**
     * 可供所有类调用的显示Toast方法
     *
     * @param context
     * @param s
     */
    public static void showToast(Context context, String s) {
        if (toastDialog == null) {
            toastDialog = new ToastDialog(context);
            toastDialog.setText(s).setDuration(2000);
        } else {
            toastDialog.setText(s);
        }
//        toastDialog.setAlignment(LayoutAlignment.CENTER);
        toastDialog.show();
    }

}
